<?php

/**
 * @author     Thibaut Cromphaut, Gaïtano Boeraeve, Matthias Mercy
 * @copyright  Copyright (c) 2011 memorygame
 */


abstract class Ahs_Model_Mapper extends Ahs_Model
{

    /**
     * @var Zend_Db_Table_Abstract
     */
    protected $_dbTable;
    /**
     * @var string
     */
    protected $_dbTableName;
    /**
     * @var array
     */
    protected $_propertiesMap = array();
    
    /**
     * @return string 
     */
    public function getDbTable()
    {
        if (null === $this->_dbTable) {
            $this->setDbTable($this->_dbTableName);
        }
        return $this->_dbTable;
    }
    /**
     * @param string $dbTable
     * @return Ahs_Model_Mapper 
     */
    public function setDbTable($dbTable)
    {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
        return $this;
    }
    
    /**
     * @return string 
     */
    public function getDbTableName()
    {
        return $this->_dbTableName;
    }
    /**
     * @param string $dbTableName 
     */
    public function setDbTableName($dbTableName)
    {
        $this->_dbTableName = $dbTableName;
    }
    
    /**
     * PropertiesMap
     * Bind the Object's Properties to its database-column
     * 
     * @return Array
     */
    public function getPropertiesMap()
    {
        return $this->_propertiesMap;
    }
    /**
     * @param array $propertiesmap;
     */
    public function setPropertiesMap($propertiesMap)
    {
        $this->_propertiesMap = $propertiesMap;
    }
    
    /**
     *
     * @param string $property
     * @return string databasecolumn 
     */
    public function getColumn($property)
    {
        if(isset($this->_propertiesMap[$property]))
        {
            return $this->_propertiesMap[$property];
        }
        
        // If we get here, we need to push an error, the porperty requested does not exist
        throw new Exception(get_class($this).'->getColumn("'.$property.'") -> Invalid property name');
    }

}


?>
